<?php
/**
 * Created by PhpStorm.
 * User: dumbledore
 * Date: 2018/3/27
 * Time: 下午3:48
 */
?>
<!DOCTYPE html>
<html>
<head>
    <!--[if lt IE 7]>
    <div class="ie6_error">还在用<strong>漏洞百出的IE6浏览器</strong>么？为了您的网络安全，请升级浏览器 <a target="_blank"
                                                                               href="http://browsehappy.com">立即升级</a>
    </div>
    <![endif]-->

    <meta charset="utf-8">
    <title>新建用户账号-成本中心-文具1号</title>
    <meta name="description"
          content="文具1号作为上海办公用品供货商公司,专为世界500强企业及SOHO办公族提供网上商城一站式办公耗材批发及采购服务,一站式选购办公日用文具用品,厂家直销,好货又便宜【阳光采购就上文具1号 阳光价格 老板放心 品质保障 员工省力】"/>
    <meta name="keywords" content="办公用品,办公文具,办公文具网站,文具网站,办公用品网,文具采购网,金万年"/>
    <meta name="copyright" content="上海易推信息科技有限公司"/>
    <meta name="renderer" content="webkit">
    <base href="<?php echo base_url(); ?>"/>
    <link rel="shortcut icon" href="favicon.ico"/>
    <link rel="stylesheet" href="public/js/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="public/css/base.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/common.css"/>
    <link href="public/css/city-picker.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="public/css/index.css?v=2222222"/>
    <!--[if lte IE 9]>
    <script type="text/javascript" src="public/js/html5shiv-printshiv-3.js"></script>
    <![endif]-->
</head>
<body>
<div class="bg bg-fff">
    <!--common - head -->
    <?php $this->load->view('common/header.php');?>
    <!--common - head end-->

    <div class="container">
        <div class="workbench-container">
            <div class="workbench-detail-container">
                <p class="path-tit">
                    <a href="<?php echo base_url() ?>cost_center/cost_center_index" class="color-red">成本中心</a>＞
                    <?php if ($user_info['identity'] == 3): ?>
                        编辑用户账号
                    <?php elseif ($user_info['identity'] == 2): ?>
                        编辑管理账号
                    <?php endif;?>
                </p>

                <div class="workbench-detail-box-wrapper">
                    <form class="layui-form workbench-detail-form" action="" lay-filter="userForm">

                        <div class="workbench-detail-box  workbench-detail-box-jbzl mb0">
                            <p class="workbench-detail-tit">
                                基本信息 <span class="notice">（带 <em
                                            class="color-red">*</em>为必填项，如不选择管理账户则审批直接提交至admin）</span>
                            </p>
                            <div class="workbench-detail-cont">
                                <div class="apply-payment-box">
                                    <?php if ($customer_info['identity'] == 1): ?>
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">成本中心 <em class="color-red">*</em></label>
                                            <div class="layui-input-block row">
                                                <select name="cost_center_id" lay-filter="select_cost_center_id"
                                                        id="select_cost_center_id" lay-verify="cost_center_id">
                                                    <option value="">请选择成本中心</option>
                                                    <?php if (count($cost_center_list)): ?>
                                                        <?php foreach ($cost_center_list as $item): ?>
                                                            <option value="<?php echo $item['id']; ?>" <?php if ($user_info['cost_center_id'] == $item['id']): ?>selected="selected"<?php endif;?>><?php echo $item['name']; ?></option>
                                                        <?php endforeach;?>
                                                    <?php endif;?>
                                                </select>
                                            </div>
                                            <a href="<?php echo base_url(); ?>cost_center/create_cost_center_index"
                                               target="_blank" class="create-cost-center-btn">+ 新建成本中心</a>
                                        </div><!--成本中心-->
                                    <?php else: ?>
                                        <input type="hidden" name="cost_center_id" value="<?php echo $user_info['cost_center_id']; ?>"/>
                                    <?php endif;?>
                                    <?php if ($customer_info['identity'] == 1 && $user_info['identity'] == 3): ?>
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">管理账户</label>
                                            <div class="layui-input-block row">
                                                <select name="parent_id" id="select_parent_id"
                                                        lay-filter="select_parent_id">
                                                    <option value="<?php echo $customer_info['id']; ?>">请选择管理账户</option>
                                                    <?php if (count($manager_list)): ?>
                                                        <?php foreach ($manager_list as $item): ?>
                                                            <option value="<?php echo $item['id']; ?>"
                                                                    data="<?php echo $item['cost_center_id']; ?>"><?php echo $item['username']; ?></option>
                                                        <?php endforeach;?>
                                                    <?php endif;?>
                                                </select>
                                            </div>
                                        </div><!--管理账户-->
                                    <?php else: ?>
                                        <input type="hidden" name="parent_id"
                                               value="<?php echo $user_info['parent_id']; ?>"/>
                                    <?php endif;?>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">账号 <em class="color-red">*</em></label>
                                        <div class="layui-input-block row" style="position: relative">
                                            <input type="text" id="jsNameInput" lay-verify="username|required"
                                                   autocomplete="off" placeholder="请输入中文、字母、数字,-,_组合，4-20个字符"
                                                   class="layui-input"
                                                   value="<?=mb_substr($user_info['username'], mb_strlen($admin_info['prefix'], "UTF-8"), mb_strlen($user_info['username'], "UTF-8"))?>"
                                                   readonly>

                                            <a href="javascript:void(0);" id="account-prefix"
                                               class="account-prefix"><?php echo $admin_info['prefix']; ?></a>

                                            <input type="hidden" name="u_prefix"
                                                   value="<?php echo $admin_info['prefix']; ?>">
                                        </div>


                                        <?php if ($user_info['status'] == 0): ?>
                                            <span class="create-cost-center-btn">该账户处于冻结状态！<a href="javascript:;"
                                                                                              class="unfreeze-account-btn unfreeze-account"
                                                                                              user_customer_id="<?=$user_info['id']?>">+  解冻该账户</a>
                                        </span>
                                        <?php else: ?>
                                            <a href="javascript:;" class="create-cost-center-btn freeze-account"
                                               user_customer_id="<?=$user_info['id']?>">+ 冻结该账户</a>
                                        <?php endif;?>
                                    </div><!--账号-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">密码 <em class="color-red">*</em></label>
                                        <div class="layui-input-block">
                                            <input type="password" name="password" id="L_pass" lay-verify="pass"
                                                   autocomplete="off" placeholder="建议使用字母、数字和符号两种及以上的组合，6-20个字符。为空则不修改"
                                                   class="layui-input">
                                        </div>
                                    </div><!--密码-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">确认密码 <em class="color-red">*</em></label>
                                        <div class="layui-input-block">
                                            <input type="password" name="repassword" lay-verify="repass"
                                                   autocomplete="off" placeholder="请再次输入密码" class="layui-input">
                                        </div>
                                    </div><!--密码-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">联系人 <em class="color-red">*</em></label>
                                        <div class="layui-input-block">
                                            <input type="text" name="name" lay-verify="name|required"
                                                   value="<?=$user_info['name']?>" autocomplete="off"
                                                   placeholder="请输入联系人" class="layui-input">
                                        </div>
                                    </div><!--联系人-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">手机号码 <em class="color-red">*</em></label>
                                        <div class="layui-input-block">
                                            <input type="tel" name="tel" lay-verify="phone"
                                                   value="<?=$user_info['tel']?>" autocomplete="off"
                                                   id="tel_1" placeholder="建议使用常用手机" class="layui-input">
                                        </div>
                                    </div><!--联系方式-->
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">电子邮箱 <em class="color-red">*</em></label>
                                        <div class="layui-input-block">
                                            <input type="email" name="email" lay-verify="email"
                                                   id="email_1" value="<?=$user_info['email']?>" autocomplete="off"
                                                   placeholder="建议使用常用邮箱" class="layui-input">
                                        </div>
                                    </div><!--联系方式-->

                                </div>

                            </div>
                        </div>

                        <div class="workbench-detail-box workbench-detail-box-jbzl" style="height: auto">
                            <p class="workbench-detail-tit" id="set-budget">
                                预算设置 <span class="notice">（预算周期为自然月，如无预算限定可不填）</span>
                            </p>
                            <div class="workbench-detail-cont workbench-detail-1">
                                <div class="create-management-account-wrapper">
                                    <div class="management-account-item">
                                        <p class="tit color-red">额度预算</p>
                                        <p class="name">每月额度</p>
                                        <div class="input-management-account-box">
                                            <input type="text" name="total_quota"
                                                   value="<?=$user_quota['total_quota']?>" lay-verify="n_number1"
                                                   class="input-management-account"
                                                   placeholder="请输入金额">
                                            <span class="unit">元</span>
                                        </div>
                                    </div>
                                    <div class="management-account-item">
                                        <p class="tit">单品额度</p>
                                        <p class="name">可设置单品购买最高额度</p>
                                        <div class="input-management-account-box">
                                            <input type="text" name="single_quota"
                                                   value="<?=$user_quota['single_quota']?>" lay-verify="n_number2"
                                                   class="input-management-account"
                                                   placeholder="请输入金额">
                                            <span class="unit">元</span>
                                        </div>
                                    </div>
                                    <div class="management-account-item">
                                        <p class="tit color-red">指定商品</p>
                                        <div class="table-box">
                                            <p class="table-row">
                                                <span class="name">清单名称</span>
                                                <span class="num">商品数</span>
                                            </p>
                                            <div id="list-div" style="overflow-y: scroll;height: 100px;">
                                                <?php foreach ($edit_centerlist as $list): ?>
                                                    <p class="table-row" data="<?php echo $list['id'] ?>">
                                                        <input type="hidden" name="list_ids[]"
                                                               value="<?php echo $list['id'] ?>"/>
                                                        <span class="table-row-name">  <?php echo $list['name'] ?></span>
                                                        <span class="table-row-num"><?php echo $list['total_num'] ?></span>
                                                        <a href="javascript:;" class="table-row-delete">删除</a>
                                                    </p>
                                                <?php endforeach;?>
                                            </div>


                                        </div>
                                        <a href="javascript:;" class="btn-add-list">+ 添加清单</a>
                                        <span class="cont-num">共计：<label
                                                    id="l-count"><?php echo count($edit_centerlist) ?></label>
                                            个清单
<!--                                            <label-->
<!--                                                    id="p-count">--><?php //echo array_sum($edit_centertotal) ?><!--</label>件商品</span>-->
                                        <!--                                        <a href="javascript:;" class="cancel">取消额度限制</a>-->
                                    </div>


                                </div>
                            </div>
                        </div>

                        <div class="workbench-detail-box workbench-detail-box2 workbench-detail-box-jbzl"
                             id="address-workbench-detail-cont">
                            <div id="address-detail-cont">
                                <p class="workbench-detail-tit">
                                    收货地址 <span class="notice">（选填）</span>
                                </p>
                                <div class="workbench-detail-cont pb0">
                                    <div class="management-account-address-wrapper">
                                        <div class="all-address-list-display">
                                            <?php if ($manager_address_list): ?>

                                                <?php foreach ($manager_address_list as $item): ?>
                                                    <div class="management-account-address-item">
                                                        <p class="tit-box">
                                                            <span class="name"
                                                                  title="<?php echo $item['name']; ?>"><?php echo mb_substr($item['name'], 0, 3, "utf-8"); ?>
                                                                ...</span>
                                                            <span class="phone"><?php echo $item['phone']; ?></span>
                                                        </p>
                                                        <p class="address">
                                                            <?php echo $item['province']; ?> <?php echo $item['city']; ?> <?php echo $item['district']; ?>
                                                            <br>
                                                            <span class="address-detail"
                                                                  title="<?php echo $item['address']; ?>"><?php echo mb_substr($item['address'], 0, 20, "utf-8"); ?></span>
                                                        </p>
                                                        <a href="javascript:;"
                                                           class="set-default default-address <?php if ($item['is_default'] == 1): ?> default <?php endif;?>"
                                                           val="<?php echo $item['id'] ?>">默认地址</a>

                                                        <a href="javascript:;" class="edit updateAddress"
                                                           val="<?php echo $item['id'] ?>">修改</a>
                                                    </div>
                                                <?php endforeach;?>

                                            <?php endif;?>
                                        </div>
                                        <a href="javascript:;" class="management-account-add-address-item"
                                           id="add_address_info">
                                            <span class="icon bg-icon_add_big_grey"></span>
                                            <p class="add-address-p">
                                                新增收货地址
                                            </p>
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </div>


                        <div class="workbench-detail-box workbench-detail-box2 workbench-detail-box-jbzl"
                             id="invoice-workbench-detail-cont">
                            <div id="invoice-detail-cont">
                                <p class="workbench-detail-tit">
                                    发票抬头 <span class="notice">（选填）</span>
                                </p>
                                <div class="workbench-detail-cont">
                                    <div class="management-account-invoice-wrapper">

                                        <?php if ($manager_invoice_list): ?>
                                            <?php foreach ($manager_invoice_list as $value): ?>
                                                <div class="management-account-invoice-item">
                                                    <p class="company" title="<?=$value['invoice_company_name']?>">
                                                        <?=mb_substr($value['invoice_company_name'], 0, 20)?>
                                                    </p>
                                                    <a href="javascript:;"
                                                       class="set-default <?php if ($value['is_default'] == 1): ?>default<?php endif;?> default-look-up"
                                                       val="<?=$value['id']?>">默认抬头</a>
                                                    <a href="javascript:;" class="edit updateInvoice"
                                                       val="<?=$value['id']?>"
                                                       type="<?=$value['invoice_type']?>">修改</a>
                                                </div>
                                            <?php endforeach;?>
                                        <?php endif;?>

                                        <a href="javascript:;" id="add_invoice_info"
                                           class="management-account-add-invoice-item">
                                            <span class="icon bg-icon_add_big_grey"></span>
                                            <p class="add-address-p">
                                                新增发票
                                            </p>
                                        </a>
                                    </div>
                                </div>

                                <input type="hidden" name="customer_id" value="<?=$user_id?>"><!--被编辑用户customer_id-->
                            </div>
                        </div>
                        <button class="layui-btn btn-add" lay-submit lay-filter="userForm1">保存</button>

                    </form>
                </div>
            </div>

        </div>

    </div>

    <?php $this->load->view('common/bottom.php');?>
</div>
<div class="mask none"></div>
<!--隐藏 添加 class  none-->
<div id="add_address_div" class="pop pop-add-address none" style="width: 675px;>
    <a href=" javascript:;
" class="close bg-btn_close_grey_n"></a>
<p class="tit">新增地址</p>
<div class="cont">
    <form class="layui-form pop-add-address-form workbench-detail-form" id="add_address_form">
        <div class="pop-add-address-box">
            <div class="layui-form-item">
                <label class="layui-form-label">收货人姓名 <em class="color-red">*</em></label>
                <div class="layui-input-block">
                    <input type="text" id="name" name="name" lay-verify="required"
                           autocomplete="off" style="float:left;" placeholder="请输入姓名"
                           class="layui-input">
                </div>
            </div><!--账号-->

            <div class="layui-form-item">
                <label class="layui-form-label">所 在 地 区<em class="color-red">*</em></label>
                <div class="layui-input-block">
                    <div class="city-box">
                        <div id="distpicker1">
                            <div class="form-group">
                                <div style="position: relative;">
                                    <input id="city-picker1" class="form-control" readonly
                                           type="text" value="请选择省/市/区"
                                           data-toggle="city-picker" size="70">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div><!--企业所在地-->
            <div class="layui-form-item">
                <label class="layui-form-label">街 道 地 址<em class="color-red">*</em></label>
                <div class="layui-input-block">
                    <input type="text" name="address" id="address" required
                           lay-verify="required"
                           placeholder="请输入详细地址" style="width:434px" autocomplete="off"
                           class=" layui-input">
                </div>
            </div><!--街 道 地 址-->
            <div class="layui-form-item">
                <label class="layui-form-label">邮 政 编 码</label>
                <div class="layui-input-block">
                    <input type="tel" name="postcode" id="postcode" lay-verify="name" autocomplete="off"
                           placeholder="请填写6位邮政编码" class="layui-input">
                </div>
            </div><!--密码-->

            <div class="layui-form-item">
                <label class="layui-form-label">手 机 号 码 <em class="color-red">*</em></label>
                <div class="layui-input-block">
                    <input type="tel" name="phone" id="phone" lay-verify="phone"
                           autocomplete="off" placeholder="请输入联系方式" class="layui-input">
                </div>
            </div><!--联系方式-->
            <div class="layui-form-item">
                <label class="layui-form-label">电 话 号 码 </label>
                <div class="layui-input-block">
                    <input type="text" name="tel" id="tel" autocomplete="off" placeholder="请输入区号-电话号码-区号"
                           class="layui-input">
                </div>
            </div><!--联系方式-->
            <input type="hidden" name="address_id" id="address_id">
            <input type="hidden" name="regionId" id="regionId">
            <input type="hidden" name="user_id" id="user_id" value="<?=$user_id?>">
        </div>
        <div class="checkbox-box">
            <input type="checkbox" name="is_address_default" id="is_address_default" lay-skin="primary"
                   title="设置为默认收货地址" checked="">
        </div>
        <div class="btn-box">
            <input type="hidden" value="" name="address_id" id="address_id">
            <a href="javascript:;" class="btn-submit" onclick="change_param()">保存</a>
            <a href="javascript:;" class="btn-cancel address-cancel">取消</a>
        </div>

    </form>
</div>
</div><!--新增地址-->
<div id="add_invoice_div" class="pop pop-add-address none">
    <a href="javascript:;" class="close bg-btn_close_grey_n"></a>
    <p class="tit">发票抬头</p>
    <div class="cont">
        <form class="layui-form  pop-add-address-form workbench-detail-form" action="" id="add_invoice_form">
            <div class="radio-box">
                <input type="radio" name="type" id="type1" value="2" title="增值税专用发票信息" checked="" lay-filter="type">
                <input type="radio" name="type" id="type2" value="4" title="增值税普通发票信息" lay-filter="type">
            </div>
            <div class="pop-add-address-box">
                <div class="layui-form-item">
                    <label class="layui-form-label">单 位 名 称 <em class="color-red">*</em></label>
                    <div class="layui-input-block">
                        <input type="text" name="title" lay-verify="title" id="title" autocomplete="off"
                               style="float:left;" placeholder="请输入详细的单位名称" class="layui-input">
                    </div>
                </div><!--账号-->

                <div class="layui-form-item">
                    <label class="layui-form-label">纳税人识别码<em class="color-red">*</em></label>
                    <div class="layui-input-block">
                        <input type="text" name="qycode" required id="qycode" placeholder="请输入纳税人识别码"
                               style="width:434px" autocomplete="off" class=" layui-input">
                    </div>
                </div><!--纳税人识别码-->
                <div class="layui-form-item">
                    <label class="layui-form-label">注 册 地 址<em class="color-red">*</em></label>
                    <div class="layui-input-block">
                        <input type="tel" name="invoice_address" lay-verify="invoice_address" autocomplete="off"
                               placeholder="请输入详细地址" style="width:434px" class="layui-input">
                    </div>
                </div><!--地  址-->

                <div class="layui-form-item">
                    <label class="layui-form-label">注 册 电 话<em class="color-red">*</em></label>
                    <div class="layui-input-block">
                        <input type="tel" name="invoice_tel" lay-verify="invoice_tel" autocomplete="off"
                               placeholder="请输入注册电话" class="layui-input">
                    </div>
                </div><!--联系方式-->
                <div class="layui-form-item">
                    <label class="layui-form-label">开 户 银 行<em class="color-red">*</em></label>
                    <div class="layui-input-block">
                        <input type="text" name="bank" lay-verify="bank" autocomplete="off"
                               placeholder="请输入开户银行名称" class="layui-input">
                    </div>
                </div><!--开  户  银  行-->
                <div class="layui-form-item">
                    <label class="layui-form-label">银 行 账 户<em class="color-red">*</em></label>
                    <div class="layui-input-block">
                        <input type="tel" name="card" lay-verify="card" autocomplete="off"
                               placeholder="请输入银行账户" style="width:434px" class="layui-input">
                    </div>
                </div><!--银  行  账  户-->
                <input type="hidden" name="invoice_id" id="invoice_id">
            </div>
            <div class="checkbox-box">
                <input type="checkbox" name="is_invoice_default" id="is_invoice_default" lay-skin="primary"
                       title="设置为默认发票抬头">
            </div>


            <div class="btn-box">
                <a href="javascript:;" class="btn-submit" onclick="invoice_param()">保存</a>
                <a href="javascript:;" class="btn-cancel invoice-cancel">取消</a>
            </div>

        </form>
    </div>
</div><!--新增发票抬头-->
<div class="pop pop-account-activation bg-padding-inside none unfreeze" style="height: 283px">
    <a href="javascript:;" class="close bg-btn_close_n"></a>
    <p class="top-tit">
        <span class="bg-logo_popup"></span>
    </p>
    <div class="cont">
        <p class="tit">解冻账户</p>
        <p class="intro">
            解冻后该账户即可正常登陆文具1号企业用户采购系统。
        </p>
        <div class="btn-box">
            <button class="adjustment-budget-submit adjustment-budget-unfreeze-submit">确 定</button>
        </div>
    </div>
</div>  <!--解冻账户-->
<div class="pop pop-account-change-msg bg-padding-inside none notice-mamager-user" style="height: 283px">
    <a href="javascript:;" class="close bg-btn_close_n"></a>
    <p class="top-tit">
        <span class="bg-logo_popup"></span>
    </p>
    <div class="cont">
        <p class="intro">
            账期用户对成本中心的信息变更将提交至平台存留依据<br>
            通知您的下级账户
        </p>
        <form class="layui-form workbench-detail-form" action="">
            <div class="layui-form-item">
                <p class="p01">请选择通知方式：</p>
                <div class="layui-input-block apply-payment-radio-box" style="margin-left:0;">
                    <input type="radio" name="notice" value="1" title="邮件通知" checked>
                    <input type="radio" name="notice" value="2" title="短信通知">
                </div>
            </div><!--请选择通知方式-->
        </form>
        <div class="btn-box">
            <a href="javascript:;" class="btn-cancel notice-cancel">取消</a>
            <a href="javascript:;" class="btn-submit notice-info">确定</a>
        </div>
    </div>
</div>  <!--请选择通知方式-->
<div class="pop pop-account-activation bg-padding-inside none freeze" style="height: 283px">
    <a href="javascript:;" class="close bg-btn_close_n"></a>
    <p class="top-tit">
        <span class="bg-logo_popup"></span>
    </p>
    <div class="cont">
        <p class="tit">冻结账户</p>
        <p class="intro">
            冻结后该账户将无法正常登陆文具1号企业用户采购系统。
            请谨慎操作！
        </p>
        <div class="btn-box">
            <button class="adjustment-budget-submit adjustment-budget-freeze-submit">确 认</button>
        </div>
    </div>
</div>  <!--冻结账户-->


<?php if (empty($center)): ?>
    <div class="pop pop-add-list bg-padding-inside none addrcost" style="height: 454px">
        <a href="javascript:;" class="close bg-btn_close_n"></a>
        <p class="top-tit">
            <span class="bg-logo_popup"></span>
            <span class="top-tit-text">添加清单</span>
        </p>
        <div class="cont pop-add-list-cont">
            <span class="icon-none bg-img_nonedate"></span>
            <p class="icon-none-p">没有清单</p>
            <?php if ($customer_info['identity'] == 2): ?>
                <button class="adjustment-budget-submit adjustment-budget-list-submit" style="float: none">确 认</button>
            <?php else: ?>
                <a target="_blank" href="<?php echo $this->config->item("shop_url") ?>mMPur-mylist.html"
                   class="adjustment-budget-submit" style="float: none;">+ 新建清单</a>
            <?php endif;?>
        </div>
    </div>
<?php else: ?>
    <!--    <form action="cost_center/create_cost_center" method="post">-->
    <input type="hidden" name="name" value="" id="name">
    <input type="hidden" name="id" value="" id="list_id">
    <div class="pop pop-add-list bg-padding-inside none addrcost" style="height: 454px">
        <a href="javascript:;" class="close bg-btn_close_n"></a>
        <p class="top-tit">
            <span class="bg-logo_popup"></span>
            <span class="top-tit-text">添加清单</span>
        </p>
        <div class="cont pop-add-list-cont">
            <p class="pop-add-list-row pop-add-list-row-line" style="padding-left:50px;">
                <!--<span class="checkbox bg-btn_select_xieyi_h"></span>-->
                <?php if ($customer_info['identity'] == 1): ?>
                    <span class="name">清单名称（<?php echo count($center) ?>）</span>
                <?php elseif ($customer_info['identity'] == 2): ?>
                    <span class="name">清单名称（<?php echo count($user_centerlist) ?>）</span>
                <?php endif;?>
                <span class="num">商品总数</span>
                <span class="money">金额</span>
            </p>
            <div class="pop-add-list-table">

                <!--            <p class="pop-add-list-row">-->
                <!--                <span class="checkbox checkbox-checked"></span>-->
                <!--                <span class="name">销售部限定采购商品清单名称清单名单名称清单名清单名称…</span>-->
                <!--                <span class="num">20</span>-->
                <!--                <span class="money">￥1300.00</span>-->
                <!--            </p>-->
                <?php if ($customer_info['identity'] == 1): ?>
                    <?php foreach ($center as $cen): ?>
                        <p class="pop-add-list-row" id="<?php echo $cen['id'] ?>">
                            <span class="checkbox <?php if (in_array($cen['id'], $edit_costlist)): ?> checkbox-checked <?php endif;?> "></span>
                            <span class="name"><?php echo $cen['name'] ?></span>
                            <span class="num"><?php echo $cen['total_num'] ? $cen['total_num'] : 0 ?></span>
                            <span class="money">￥<span class="money1"><?php echo $cen['amount'] ?></span></span>
                        </p>
                    <?php endforeach;?>
                <?php elseif ($customer_info['identity'] == 2): ?>
                    <?php foreach ($user_centerlist as $cen): ?>
                        <p class="pop-add-list-row" id="<?php echo $cen['id'] ?>">

                            <span class="checkbox <?php if (in_array($cen['id'], $edit_costlist)): ?> checkbox-checked <?php endif;?> "></span>
                            <span class="name"><?php echo $cen['name'] ?></span>
                            <span class="num"><?php echo $cen['total_num'] ? $cen['total_num'] : 0 ?></span>
                            <span class="money">￥<span class="money1"><?php echo $cen['amount'] ?></span></span>
                        </p>
                    <?php endforeach;?>

                <?php endif;?>
            </div>
            <span class="add-list-max">
            已选择：<lable id="lists_count"><?php echo count($edit_costlist) ?></lable>个清单
<!--                共计<lable-->
<!--                        id="lists_product_count">--><?php //echo array_sum($edit_centertotal) ?><!--</lable> 件商品  合计 <em-->
<!--                        class="color-red"><lable id="lists_money">--><?php //echo $edit_amount ?><!--</lable>元</em>-->
            <?php if ($customer_info['identity'] == 1): ?>
            <a style="margin-left: 200px;font-size: 12px;" class="add-list" target="_blank" href="<?php echo $this->config->item("shop_url") ?>mMPur-mylist.html">添加清单</a>
            <?php endif;?>
            </span>

            <button class="adjustment-budget-submit adjustment-budget-list-submit">确 认</button>
        </div>
    </div>
    <!--    </form>-->
<?php endif;?>


<script type="text/javascript" src="public/js/jquery.min.js"></script>
<script src="public/js/layui/layui.js"></script>
<script src="public/js/city-picker.data.js"></script>
<script src="public/js/city-picker1.js"></script>
<script type="text/javascript" src="public/js/index.js"></script>
<script>
    (function () {
        var _name_width = $('#account-prefix').width() + 13;
        console.log(_name_width);
        $('#jsNameInput').css('text-indent', _name_width);
    })();

    $(function () {
        $('#select_cost_center_id').val("<?php echo $user_info['cost_center_id']; ?>");
        $('#select_parent_id').val("<?php echo $user_info['parent_id']; ?>");
    })
    layui.use(['form', 'layedit', 'laydate', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit;
        var $ = layui.jquery
            , upload = layui.upload;

        var is_account = "<?=$is_account?>";

        form.on('select(select_parent_id)', function (data) {
            $('#select_cost_center_id').val($(data.elem[data.elem.selectedIndex]).attr('data'));
            form.render('select');
        });

        form.on('select(select_cost_center_id)', function (data) {
            var data = $(data.elem[data.elem.selectedIndex]).attr('value');
            if(data != ""){
                $("#select_parent_id").empty();
                var html =  "<option value=<?php echo $customer_info['id']; ?>>请选择管理账户</option>";
                var manager_list = <?php echo json_encode($manager_list) ?>;
                for(var i=0;i<manager_list.length;i++){

                    if(data == manager_list[i].cost_center_id){
                        html += "<option value="+manager_list[i].id+" data="+manager_list[i].cost_center_id+">"+manager_list[i].username+"</option>";
                    }
                }
                
            }else{
                $("#select_parent_id").empty();
                var html =  "<option value=<?php echo $customer_info['id']; ?>>请选择管理账户</option>";
                var manager_list = <?php echo json_encode($manager_list) ?>;
                for(var i=0;i<manager_list.length;i++){
                    html += "<option value="+manager_list[i].id+" data="+manager_list[i].cost_center_id+">"+manager_list[i].username+"</option>";
                }
            }
            $("#select_parent_id").append(html);
            $('#select_parent_id').val(0);
            form.render('select');
        });

        form.verify({
            cost_center_id: function (value, item) {
                if (value == "") {
                    $("html, body").animate({
                        scrollTop: "0px"
                    }, {
                        duration: 0,
                        easing: "swing"
                    });
                    return '请选择成本中心';
                }
            },
            username: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (value == "") {
                    return '账号不可为空';
                }
                if (value.length < 4 || value.length > 20) {
                    return '请输入4-20个字符';
                }
                if (!/^[\u4E00-\u9FA5A-Za-z0-9_-]+$/.test(value)) {
                    return '请输入中文、字母、数字,"-","_"组合';
                }
            }
            , name: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (value == "") {
                    return '联系人不可为空';
                }
                if (value.length < 2 || value.length > 10) {
                    return '请输入2-10个字符';
                }
            }
            , n_number1: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (value && isNaN(value)) {
                    return '每月额度只能填写数字';
                }
                if (value < 0) {
                    return '每月额度必需大于0';
                }
                if (value > 100000) {
                    return '每月额度必需小于100000';
                }
            }
            , n_number2: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (value && isNaN(value)) {
                    return '单品额度只能填写数字';
                }
                if (value < 0) {
                    return '单品额度必需大于0';
                }
                if (value > 100000) {
                    return '单品额度必需小于100000';
                }
            }
            , phone: function (value, item) {
                if (value == "") {
                    return '手机号码不可为空';
                }
                if (!/^1[345789]{1}\d{9}$/.test(value)) {
                    return '输入的手机格式错误';
                }
            }
            , email: function (value, item) {
                if (value == "") {
                    return '邮箱地址不可为空';
                }
                if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value)) {
                    return '输入的邮箱地址格式错误';
                }
            }
            , pass: function (value, item) {
                if (value != "") {
                    if (value.length < 6 || value.length > 20) {
                        return '请输入6-20个字符';
                    }
                    var arr = new Array();
                    arr = value.split(" ");
                    if (arr.length != 1) {
                        return '密码只能是字母，数字，常用符号的组合';
                    }
                }
            }
            , repass: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (value != "") {
                    var repassvalue = $('#L_pass').val();
                    if (value != repassvalue) {
                        return '两次输入的密码不一致!';
                    }
                }
            }
        });

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/upload/'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
        var uploadInst2 = upload.render({
            elem: '#test2'
            , url: '/upload/'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo2').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
        var uploadInst3 = upload.render({
            elem: '#test3'
            , url: '/upload/'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo3').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        form.on('radio(type)', function (data) {
            if (data.value == 4) {
                $("#add_invoice_form .layui-form-item").each(function (e) {
                    if (e > 1) {
                        $(this).css('display', 'none');
                    }
                });
            } else {
                $('#add_invoice_form .layui-form-item').css('display', 'block');
            }
        });

        //监听提交
        form.on('submit(userForm1)', function (data) {
            $.ajax({
                type: "post",
                dataType: "json",
                url: "<?php echo base_url() ?>cost_center/edit_manager_user",
                data: data.field,
                async: false,
                success: function (data) {
                    if (data.code == 0) {
                        if (is_account == 0) {
                            location.href = "<?php echo base_url(); ?>cost_center/cost_center_index"
                        } else {
                            $('.notice-mamager-user').removeClass('none');
                            $('.notice-mamager-user').show();
                            $('.mask').removeClass('none');
                            $('.mask').show();
                        }
                        // $('.notice-mamager-user').addClass('none');
                        // $('.notice-mamager-user').hide();
                        // $('.mask').addClass('none');
                        // $('.mask').hide();
                        //layer.msg("保存成功");
                        // setTimeout(function () {
                        //     location.href = "<?php echo base_url(); ?>cost_center/cost_center_index"
                        // }, 2000)
                    } else {
                        if (data.msg == "该手机号已被注册") {
                            var a = $('#tel_1').offset().top;
                            $("html,body").animate({scrollTop: a}, 'slow');
                            layer.msg(data.msg);
                            return false;
                        }
                        if (data.msg == "该账号已被注册") {
                            var a = $('#jsNameInput').offset().top;
                            $("html,body").animate({scrollTop: a}, 'slow');
                            layer.msg(data.msg);
                            return false;
                        }
                        if (data.msg == "该电子邮箱地址已存在") {
                            var a = $('#email_1').offset().top;
                            $("html,body").animate({scrollTop: a}, 'slow');
                            layer.msg(data.msg);
                            return false;
                        }
                        if (data.msg == "由于上级账号每月额度有限制，所以此账号每月额度必须也有限制，请重新分配每月额度限制") {
                            var a = $('.workbench-detail-1').offset().top;
                            $("html,body").animate({scrollTop: a}, 'slow');
                            layer.msg(data.msg);
                            return false;
                        }
                        if (data.msg == "由于该manager创建user分配的单品额度存在超出您现在设置的单品额度，请先修改该用户创建的user单品额度") {
                            var a = $('.workbench-detail-1').offset().top;
                            $("html,body").animate({scrollTop: a}, 'slow');
                            layer.msg(data.msg);
                            return false;
                        }
                        if (data.msg == "由于该manager创建user分配的每月额度总和超出您现在设置的每月额度，请先修改该用户创建的user每月额度") {
                            var a = $('.workbench-detail-1').offset().top;
                            $("html,body").animate({scrollTop: a}, 'slow');
                            layer.msg(data.msg);
                            return false;
                        }
                        if (data.msg == "新密码不能与原密码相同") {
                            var a = $('#L_pass').offset().top;
                            $("html,body").animate({scrollTop: a}, 'slow');
                            layer.msg(data.msg);
                            return false;
                        }
                        layer.msg(data.msg)
                    }
                }
            });

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>

<script type="text/javascript">
    $(function () {
        $('.notice-cancel').click(function () {
            $('.notice-mamager-user').addClass('none');
            $('.notice-mamager-user').hide();
            $('.mask').addClass('none');
            $('.mask').hide();
        })
        $('.notice-info').unbind('click').click(function () {
            var type = $('input[name=notice]:checked').val();
            $.ajax({
                type: "post",
                dataType: "json",
                url: "<?php echo base_url() ?>cost_center/send_email_phone",
                data: {type: type},
                async: false,
                success: function (data) {
                    if (data.code == 0) {
                        $('.notice-mamager-user').addClass('none');
                        $('.notice-mamager-user').hide();
                        $('.mask').addClass('none');
                        $('.mask').hide();
                        layer.msg("保存成功");
                        setTimeout(function () {
                            location.href = "<?php echo base_url(); ?>cost_center/cost_center_index"
                        }, 2000)
                    } else {
                        layer.alert(data.msg)
                    }
                }
            });
        })
        $("#city-picker1").citypicker();
        $('.btn-add-list').click(function (e) {
            $('.mask').removeClass('none')
            $('.mask').show();
            $('.addrcost').removeClass('none')
            $('.addrcost').show();
            e.stopPropagation();
        });

        $(".show-all-address").click(function () {
            $(this).toggleClass('show-all-up');
            if ($(this).hasClass('show-all-up')) {
                $(this).html('收起全部地址');
            } else {
                $(this).html('显示全部地址');
            }
        });
        $(".show-all-title").click(function () {
            $(this).toggleClass('show-all-up');
            if ($(this).hasClass('show-all-up')) {
                $(this).html('收起全部抬头');
            } else {
                $(this).html('显示全部抬头');
            }
        });
        $(".checkbox").click(function () {

            $(this).toggleClass('checkbox-checked');

            $("#lists_count").html($(".checkbox-checked ").length);
            var num = 0;
            var money = 0.00;
            $(".checkbox-checked ").each(function (i, ele) {
                num += parseInt($(ele).parent().find('.num').html());
            })
            $(".checkbox-checked ").each(function (i, ele) {
                money += parseFloat($(ele).parent().find('.money1').html());
            })
            $("#lists_product_count").html(num);
            $("#lists_money").html(money.toFixed(2));
        })


        $("body").on("click", ".table-row-delete", function () {
            var count = $("#l-count").html();
            var id = $(this).parent().attr('data');
            var good_num = $(this).prev('.table-row-num').html();
            var goods_num1 = $("#lists_product_count").html()
            var goods_num2 = $("#p-count").html()
            var good_money = $("#" + id + "").find('.money1').html();
            var goods_money = $("#lists_money").html();
            $("#" + id + "").find('.checkbox').removeClass('checkbox-checked');
            $(this).parent().remove();
            $("#l-count").html(count - 1);
            $("#lists_count").html(count - 1);
            $("#lists_product_count").html(goods_num1 - good_num);
            $("#p-count").html(goods_num2 - good_num);
            $("#lists_money").html(parseFloat(goods_money - good_money).toFixed(2));
        })

        $(".adjustment-budget-list-submit").click(function () {
            var name = $(".checked").children('.name').text();
            console.log(name);
            var id = $(".checked").children('.id').text();
            var arr = [];
            var ids = '';
            var html = '';
            $('.checkbox-checked').each(function (i, ele) {
                $(ele).parent().find('.name').html();
                $(ele).parent().find('.num').html();
                ids += $(ele).parent().attr('id') + ',';
                html += '<p class="table-row" data="' + $(ele).parent().attr('id') + '">' +
                    '<input type="hidden" name="list_ids[]" value="' + $(ele).parent().attr('id') +
                    '"/> ' +
                    '<span class="table-row-name">' + $(ele).parent().find('.name').html() +
                    '</span> ' +
                    '<span class="table-row-num">' + $(ele).parent().find('.num').html() +
                    '</span> ' +
                    '<a href="javascript:;" class="table-row-delete">删除</a>' +
                    '</p>';
            })
            //$.getJSON("<?php //echo base_url('cost_center/query_list');?>//?list_id=" + ids, function (re) {
            //    $("#p-count").html(re.data.goodstotal);
            //})
            $("#list-div").html(html);
            $("#l-count").html($("#lists_count").html())
            $("#p-count").html($("#lists_product_count").html())
            $('.addrcost').addClass('none')
            $('.addrcost').css('display', 'none');
            $('.mask').addClass('none')
        });
    });

    $('.notice-info').click(function () {

    })
    //冻结账户
    $('.freeze-account').click(function () {
        var user_customer_id = $(this).attr('user_customer_id');
        $('.adjustment-budget-freeze-submit').attr('user_customer_id', user_customer_id);
        $('.freeze').removeClass('none');
        $('.mask').removeClass('none');
        $('.freeze').show();
        $('.mask').show();
    })
    $('.adjustment-budget-freeze-submit').click(function () {
        var user_customer_id = $(this).attr('user_customer_id');
        $.post("<?php echo base_url() ?>cost_center/freeze_account", {id: user_customer_id}, function (res) {
            if (res.code == 0) {
                layer.msg(res.msg);
                location.reload();
            } else {
                layer.msg(res.msg);
            }
        }, "json")
        $('.freeze').addClass('none');
        $('.freeze').hide();
        $('.mask').addClass('none');
        $('.mask').hide();
    })

    //解冻账户
    $('.unfreeze-account').click(function () {
        var user_customer_id = $(this).attr('user_customer_id');
        $('.adjustment-budget-unfreeze-submit').attr('user_customer_id', user_customer_id);
        $('.unfreeze').removeClass('none');
        $('.mask').removeClass('none');
        $('.unfreeze').show();
        $('.mask').show();
    })
    $('.adjustment-budget-unfreeze-submit').click(function () {
        var user_customer_id = $(this).attr('user_customer_id');
        $.post("<?php echo base_url() ?>cost_center/unfreeze_account", {id: user_customer_id}, function (res) {
            if (res.code == 0) {
                layer.msg(res.msg);
                location.reload();
            } else {
                layer.msg(res.msg);
            }
        }, "json")
        $('.unfreeze').addClass('none');
        $('.unfreeze').hide();
        $('.mask').addClass('none');
        $('.mask').hide();
    })


    $(document).on('click', "#add_address_info", function (event) {
        $('.mask').removeClass('none')
        $(".mask").show();
        $("#add_address_form")[0].reset();
        $("#address_id").val('');
        $("#city-picker1").citypicker("reset");
        $("#add_address_div").removeClass('none');
        $("#add_address_div").show();
    })
    $(document).on('click', "#add_invoice_info", function (event) {
        $('#add_invoice_form .layui-form-item').css('display', 'block');
        $('.mask').removeClass('none')
        $(".mask").show();
        $("#add_invoice_form")[0].reset();
        $("#invoice_id").val('');
        $("#add_invoice_div").removeClass('none');
        $("#add_invoice_div").show();
    })

    function change_param() {

        var name = $("#name").val();
        var address_id = $('#address_id').val();
        if (name == "") {
            layer.alert("姓名不可为空", function () {
                $("#name").focus();
                layer.closeAll();
            });
            return false;
        }

        if (name.length < 2 || name.length > 20) {
            layer.alert("请输入2-20个字符", function () {
                $("#name").focus();
                layer.closeAll();
            });
            return false;
        }
        if (!/^[\u4E00-\u9FA5A-Za-z0-9_-]+$/.test(name)) {
            layer.alert('请输入中文、字母、数字,"-","_"组合', function () {
                $("#name").focus();
                layer.closeAll();
            });
            return false;
        }
        if (typeof($("#distpicker1 [data-count='district']").attr('data-code')) == 'undefined') {
            layer.alert("所在地区必须选择");
            return false;
        }
        var address = $("#address").val();
        if (address == "") {
            layer.alert("地址不可为空!", function () {
                $("#address").focus();
                layer.closeAll();
            });
            return false;
        }
        if (address.length < 6 || address.length > 60) {
            layer.alert("地址最少要6个字，最多不能超过60个字", function () {
                $("#address").focus();
                layer.closeAll();
            });
            return false;
        }
        if (/^[0-9]+$/.test(address)) {
            layer.alert("不能全为数字或字母", function () {
                $("#address").focus();
                layer.closeAll();
            });
            return false;
        }
        if (/^[a-z]+$/.test(address) || /^[A-Z]+$/.test(address)) {
            layer.alert("不能全为数字或字母", function () {
                $("#address").focus();
                layer.closeAll();
            });
            return false;
        }
        var postcode = $("#postcode").val();
        if (postcode) {
            if (!/^[0-9][0-9]{5}$/.test(postcode)) {
                layer.alert("请正确填写邮政编码格式", function () {
                    $("#postcode").focus();
                    layer.closeAll();
                });
                return false;
            }
        }

        var phone = $("#phone").val();
        if (phone == "") {
            layer.alert("手机号码不可为空", function () {
                $("#phone").focus();
                layer.closeAll();
            });
            return false;
        }
        if (!(/^1[34578]\d{9}$/.test(phone))) {
            layer.alert("请正确填写手机号码格式", function () {
                $("#phone").focus();
                layer.closeAll();
            });
            return false;
        }
        var tel = $("#tel").val();
        if (tel) {
            if (!/^0\d{2,3}-?\d{7,8}(-\d{1,8})?$/.test(tel)) {
                layer.alert("电话号码格式不正确", function () {
                    $("#tel").focus();
                    layer.closeAll();
                });
                return false;
            }
        }
        var address_form_obj = $("#add_address_form").serializeArray();
        address_form_obj.push({name: "province", value: $("#distpicker1 [data-count='province']").html()});
        address_form_obj.push({name: "city", value: $("#distpicker1 [data-count='city']").html()});
        address_form_obj.push({name: "district", value: $("#distpicker1 [data-count='district']").html()});
        if ($("input[name=is_address_default]").is(':checked')) {
            address_form_obj.push({name: "is_default", value: 1});
        } else {
            address_form_obj.push({name: "is_default", value: 0});
        }

        // address_form_obj.push({name: "province", value: $("#city-picker1").data("citypicker").getValue('province')});
        // address_form_obj.push({name: "city", value: $("#city-picker1").data("citypicker").getValue('city')});
        // address_form_obj.push({name: "district", value: $("#city-picker1").data("citypicker").getValue('district')});
        address_form_obj.push({name: "address_id", value: $("#address_id").val()});
        $.ajax({
            type: "post",
            dataType: "json",
            url: "<?php echo base_url() ?>cost_center/add_address",
            data: address_form_obj,
            async: false,
            success: function (data) {
                if (data.code == 0) {
                    layer.alert("保存成功");
                    // 添加收获地址栏目

                    var address_list = data.data.address_list;

                    var html = '';
                    $.each(address_list, function (key, val) {

                        html += '<div class="management-account-address-item">';
                        html += '<input type="hidden" value="' + val.id + '" class="address_list">';
                        html += '<p class="tit-box">';
                        html += '<span class="name" title="' + val.name + '">' + val.name.substring(0, 3) + '...</span>';
                        html += '<span class="phone">' + val.phone + '</span>';
                        html += '</p>';
                        html += '<p class="address">';
                        html += val.province + ' ' + val.city + ' ' + val.district + '<br>';
                        html += '<span class="address-detail" title="' + val.address + '">' + val.address.substring(0, 20) + '</span>';
                        html += '</p>';
                        if (val.is_default == 1) {
                            html += ' <a href="javascript:;" class="set-default default-address default" val="' + val.id + '">默认地址</a>';
                        } else {
                            html += ' <a href="javascript:;" class="set-default default-address" val="' + val.id + '">默认地址</a>';
                        }
                        html += '<a href="javascript:;" class="edit updateAddress" val="' + val.id + '">修改</a>';
                        html += '</div>';

                    });
                    html += '<a href="javascript:;" class="management-account-add-address-item" id="add_address_info"> <span class="icon bg-icon_add_big_grey"></span> <p class="add-address-p">新增收货地址 </p> </a>';
                    $(".management-account-address-wrapper").html(html);
                    $('.mask').addClass('none');
                    $('.mask').hide();
                    ;
                    $("#add_address_div").addClass('none');
                    $("#add_address_div").hide();
                } else {
                    layer.alert(data.msg)
                }
            }
        });
    }

    $(document).on('click', ".updateAddress", function (event) {
        event.stopPropagation();
        var id = $(this).attr('val')
        $.ajax({
            type: "post",
            dataType: "json",
            url: "<?php echo base_url() ?>cost_center/address_info",
            data: {'id': id},
            async: false,
            success: function (data) {
                if (data.code == 0) {
                    $("#add_address_form")[0].reset();
                    $("#city-picker1").citypicker();
                    $("#city-picker1").citypicker("reset");
                    $("#city-picker1").citypicker("destroy");
                    $("#city-picker1").citypicker({
                        province: data.data.province,
                        city: data.data.city,
                        district: data.data.district
                    });
                    $("#name").val(data.data.name);
                    $("#address").val(data.data.address);
                    $("#postcode").val(data.data.postcode);
                    $("#phone").val(data.data.phone);
                    if (data.data.tel.length < 4) {
                        $("#tel").val("");
                    } else {
                        $("#tel").val(data.data.tel);
                    }
                    $("#address_id").val(data.data.id);
                    $("#user_id").val("<?=$user_id?>");
                    $("#regionId").val(data.data.region_id);
                    if (data.data.is_default == 1) {
                        $("#is_default").prop("checked", true);
                    } else {
                        $("#is_default").prop("checked", false);
                    }
                    $(".mask").removeClass("none");
                    $(".mask").show();
                    $("#add_address_div").removeClass("none")
                    $("#add_address_div").show();
                } else {
                    layer.alert(data.msg)
                }
            }
        });
    })

    function invoice_param() {
        var uid = "<?=$user_id?>";
        var invoice_id = $('#invoice_id').val();
        var title = $("#title").val();
        if (title == "") {
            layer.alert("单位名称不可为空", function () {
                $("#title").focus();
                layer.closeAll();
            });
            return false;
        }
        if (title.length < 3 || title.length > 60) {
            layer.alert("单位名称必须为3-60个字符", function () {
                $("#title").focus();
                layer.closeAll();
            });
            return false;
        }
        if (!/^[\u4E00-\u9FA5A-Za-z0-9_()（）-]+$/.test(title)) {
            layer.alert("单位名称格式必须是中英文，数字,-,_,（）,()的组合", function () {
                $("#title").focus();
                layer.closeAll();
            });
            return false;
        }
        var qycode = $("#qycode").val();
        if (qycode == "") {
            layer.alert("纳税人识别码不可为空！", function () {
                $("#qycode").focus();
                layer.closeAll();
            });
            return false;
        }
        if (qycode.length != 15 && qycode.length != 18 && qycode.length != 20) {
            layer.alert("纳税人识别码格式输入错误，请核对！", function () {
                $("#qycode").focus();
                layer.closeAll();
            });
            return false;
        }

        if (!(/^\w+$/.test(qycode))) {
            layer.alert("纳税人识别码格式输入错误，请核对！", function () {
                $("#qycode").focus();
                layer.closeAll();
            });
            return false;
        }


        var type = $("input[name=type]:checked").val();
        if (type == 2) {
            var address = $("input[name=invoice_address]").val();
            if (address == "") {
                layer.alert("地址不可为空！", function () {
                    $("input[name=invoice_address]").focus();
                    layer.closeAll();
                });
                return false;
            }
            if (address.length < 6 || address.length > 60) {
                layer.alert("地址最少要6个字，最多不能超过60个字", function () {
                    $("input[name=type]:checked").focus();
                    layer.closeAll();
                });
                return false;
            }
            if (/^[0-9]+$/.test(address)) {
                layer.alert("地址不能全为数字或字母", function () {
                    $("input[name=type]:checked").focus();
                    layer.closeAll();
                });
                return false;
            }
            if (/^[a-z]+$/.test(address) || /^[A-Z]+$/.test(address)) {
                layer.alert("地址不能全为数字或字母", function () {
                    $("input[name=type]:checked").focus();
                    layer.closeAll();
                });
                return false;
            }

            var tel = $("input[name=invoice_tel]").val();
            if (tel == "") {
                layer.alert("注册电话不可为空！", function () {
                    $("input[name=invoice_tel]").focus();
                    layer.closeAll();
                });
                return false;
            }
            if (tel.length < 11 || tel.length > 20) {
                layer.alert("注册电话格式输入错误，请核对！", function () {
                    $("input[name=invoice_tel]").focus();
                    layer.closeAll();
                });
                return false;
            }
            if (!/^0\d{2,3}-?\d{7,8}(-\d{1,8})?$/.test(tel) && !/^1[345789]{1}\d{9}$/.test(tel)) {
                layer.alert("注册电话格式输入错误，请核对！", function () {
                    $("input[name=invoice_tel]").focus();
                    layer.closeAll();
                });
                return false;
            }

            var bank = $("input[name=bank]").val();
            if (bank == "") {
                layer.alert("开户银行不可为空！", function () {
                    $("input[name=bank]").focus();
                    layer.closeAll();
                });
                return false;
            }
            if (bank.length < 6 || bank.length > 30) {
                layer.alert("请输入正确的银行名称", function () {
                    $("input[name=bank]").focus();
                    layer.closeAll();
                });
                return false;
            }
            if (!/^[\u4E00-\u9FA5A-Za-z()（）]+$/.test(bank)) {
                layer.alert("请输入正确的银行名称", function () {
                    $("input[name=bank]").focus();
                    layer.closeAll();
                });
                return false;
            }

            var card = $("input[name=card]").val();
            if (card == "") {
                layer.alert("银行账户不可为空！", function () {
                    $("input[name=card]").focus();
                    layer.closeAll();
                });
            }
            if (card.length < 8 || card.length > 30) {
                layer.alert("银行账户格式输入错误，请核对！", function () {
                    $("input[name=card]").focus();
                    layer.closeAll();
                });
                return false;
            }
            if (!/^[0-9]*$/.test(card)) {
                layer.alert("银行账户格式输入错误，请核对！", function () {
                    $("input[name=card]").focus();
                    layer.closeAll();
                });
                return false;
            }
        }
        var address = $("input[name=invoice_address]").val();
        var tel = $("input[name=invoice_tel]").val();
        var card = $("input[name=card]").val();
        var bank = $("input[name=bank]").val();
        var texpayer = $("#qycode").val();
        var company = $("#title").val();
        if ($("input[name=is_invoice_default]").is(':checked')) {
            var is_default = 1;
        } else {
            var is_default = 0;
        }

        $.ajax({
            type: "post",
            dataType: "json",
            url: "<?php echo base_url() ?>cost_center/add_mdy_invoice",
            data: {
                "invoice_id": invoice_id,
                "uid": uid,
                "type": type,
                "title": title,
                "qycode": qycode,
                "address": address,
                "card": card,
                "tel": tel,
                "bank": bank,
                "is_default": is_default,
                "texpayer": texpayer,
                "company": company
            },
            async: false,
            success: function (data) {
                if (data.code == 0) {
                    layer.alert("保存成功");
                    // 添加收获地址栏目
                    var invoice_list = data.data.invoice_list;

                    var html = '';

                    $.each(invoice_list, function (key, val) {

                        html += '<div class="management-account-invoice-item">';
                        html += '<p class="company" title="' + val.invoice_company_name + '">' + val.invoice_company_name.substring(0, 20) + '</p>';
                        if (val.is_default == 1) {
                            html += ' <a href="javascript:;" class="set-default default default-look-up" val="' + val.id + '">默认发票</a>';
                        } else {
                            html += ' <a href="javascript:;" class="set-default default-look-up" val="' + val.id + '">默认发票</a>';
                        }
                        html += '<a href="javascript:;" class="edit updateInvoice" val="' + val.id + '" type="' + val.invoice_type + '">修改</a>';
                        html += '</div>';
                    });
                    html += '<a href="javascript:;" class="management-account-add-invoice-item" id="add_invoice_info"> <span class="icon bg-icon_add_big_grey"></span> <p class="add-address-p">新增发票 </p> </a>';


                    $(".management-account-invoice-wrapper").html(html);
                    $('.mask').addClass('none');
                    $('.mask').hide();
                    ;
                    $(".mask").addClass("none");
                    $(".mask").hide();
                    $("#add_invoice_div").addClass('none');
                    $("#add_invoice_div").hide();
                } else {
                    layer.alert(data.msg)
                }
            }
        });

    }

    //修改发票抬头
    $(document).on('click', ".updateInvoice", function (event) {
        event.stopPropagation();
        var id = $(this).attr('val');
        var type = $(this).attr('type');
        $.ajax({
            type: "post",
            dataType: "json",
            url: "<?php echo base_url() ?>cost_center/invoice_info",
            data: {'id': id},
            async: false,
            success: function (data) {
                if (data.code == 0) {
                    if (type == 4) {
                        $("#add_invoice_form .layui-form-item").each(function (e) {
                            if (e > 1) {
                                $(this).css('display', 'none');
                            }
                        });
                    } else {
                        $('#add_invoice_form .layui-form-item').css('display', 'block');
                    }
                    $("#add_invoice_form")[0].reset();
                    $("#title").val(data.data.invoice_company_name);
                    $("#qycode").val(data.data.invoice_code);
                    $("input[name=invoice_address]").val(data.data.invoice_address);
                    $("input[name=invoice_tel]").val(data.data.invoice_tel);
                    $("input[name=card]").val(data.data.invoice_account);
                    $("input[name=bank]").val(data.data.invoice_bank);
                    $("#invoice_id").val(id);
                    if (data.data.is_default == 1) {
                        $("#is_invoice_default").prop("checked", true);
                    } else {
                        $("#is_invoice_default").prop("checked", false);
                    }
                    if (data.data.invoice_type == 2) {
                        $("#type1").prop("checked", true);
                        $("#type2").prop("checked", false);
                    } else if ((data.data.invoice_type == 4)) {
                        $("#type1").prop("checked", false);
                        $("#type2").prop("checked", true);
                    }
                    $(".mask").removeClass("none");
                    $(".mask").show();
                    $("#add_invoice_div").removeClass("none")
                    $("#add_invoice_div").show();
                } else {
                    layer.alert(data.msg)
                }
            }
        });
    })
    //设置默认抬头
    $(document).on('click', ".default-look-up", function (event) {
        $(this).addClass('default');
        $(this).parent().siblings().find('.default-look-up').removeClass('default')
        var id = $(this).attr('val');
        var user_id = "<?=$user_id;?>";
        $.post("<?php echo base_url() ?>cost_center/default_look_up", {id: id, user_id: user_id}, function (res) {
        }, "json")
    })

    //设置默认地址
    $(document).on('click', ".default-address", function (event) {
        $(this).addClass('default');
        $(this).parent().siblings().find('.default-address').removeClass('default')
        var id = $(this).attr('val');
        var user_id = "<?=$user_id;?>";
        $.post("<?php echo base_url() ?>cost_center/default_address", {id: id, user_id: user_id}, function (res) {
        }, "json")
    })


    $(".invoice-cancel").click(function () {
        $("#add_invoice_div").css("display", "none")
        $('.mask').addClass('none')
        $('.mask').hide();
    })
    $(".address-cancel").click(function () {
        $("#add_address_div").css("display", "none")
        $('.mask').addClass('none')
        $('.mask').hide();
    })


</script>

<style type="text/css">
    .pop-add-list-cont .add-list-max {
        width: auto;
    }
    .add-list:hover{
        text-decoration:underline
    }
</style>
</body>
</html>
